package com.yijiue.ace.controller;

import com.yijiue.ace.service.DynamicRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * 动态路由
 * @author YIJIUE
 */
@RestController
@RequestMapping("/v1/routes")
public class RouteController {

    @Autowired
    private DynamicRouteService dynamicRouteService;

    @GetMapping
    public Flux<RouteDefinition> showRoutes(){
        return dynamicRouteService.selectRoute();
    }

    @PostMapping
    public void addRoutes(@RequestBody RouteDefinition routeDefinition){
        dynamicRouteService.addRoute(routeDefinition);
    }

    @DeleteMapping
    public void deleteRoutes(@RequestBody RouteDefinition routeDefinition){
        dynamicRouteService.deleteRoute(routeDefinition);
    }

    @PutMapping
    public void updateRoutes(@RequestBody RouteDefinition routeDefinition){
        dynamicRouteService.updateRoute(routeDefinition);
    }
}
